<?php
namespace admin\controllers;

use common\models\News;
use Yii;

/**
 * 资讯管理
 */
class NewsController extends BaseController
{
    public $modelClass = 'common\models\News';
    public $searchModelClass = 'admin\models\NewsSearch';

    /**
     * 置顶
     */
    public function actionUp()
    {
        $id = Yii::$app->request->get('id');

        $news = News::find();
        foreach ($news->each() as $new) {
            if ($new->id == $id) { //如果是置顶的分类
                $new->display_order = 255;
            } else {
                $new->display_order > 0 ?  $new->display_order -= 1 :  $new->display_order;
            }
            if (!$new->save()) {
                Yii::warning($new->errors);
            }

        }

        $this->back();
    }
}
